<template>
  <!-- 添加或修改线索管理对话框 -->
  <el-dialog title="添加线索" :visible="visible" width="618px" append-to-body :close-on-click-modal="false" @close="closeDailog">
    <el-form ref="form" class="cus-search-box cus-dialog-form-box" label-width="110px" :model="form" :rules="rules">
      <el-form-item label="手机号：" prop="phone">
        <el-input v-model="form.phone" placeholder="请输入手机号" />
      </el-form-item>
      <el-form-item label="渠道来源：" prop="channel">
        <el-select v-model="form.channel" filterable placeholder="请输入渠道来源">
          <el-option
            v-for="e in channelList"
            :key="e.id"
            :label="e.value"
            :value="e.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="活动信息：" prop="details">
        <el-select v-model="form.details" filterable placeholder="请选择活动信息">
          <el-option
            v-for="item in activityList"
            :key="item.id"
            :label="item.value"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="客户姓名：" prop="name">
        <el-input v-model="form.name" placeholder="请输入客户姓名" maxlength="20" />
      </el-form-item>
      <el-form-item label="性别：">
        <el-radio-group v-model="form.sex">
          <el-radio label="1">男</el-radio>
          <el-radio label="0">女</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="年龄：" prop="age">
        <el-input-number v-model="form.age" dir="rtl" :precision="0" :min="1" :max="99" :step="1" placeholder="请输入年龄" controls-position="right" />
      </el-form-item>
      <el-form-item label="微信号：" prop="weixin">
        <el-input v-model="form.weixin" placeholder="请输入微信号" maxlength="20" />
      </el-form-item>
      <el-form-item label="QQ：" prop="qq">
        <el-input v-model="form.qq" placeholder="请输入qq" maxlength="20" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button class="cus-reset-btn" @click="closeDailog">取 消</el-button>
      <el-button class="cus-search-btn" type="primary" @click="addClue">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { addClueApi } from '@/api/clue'
import { Message } from 'element-ui'
export default {
  props: {
    visible: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      form: {
        phone: '', // 手机号
        channel: '', // 渠道来源
        details: '', // 详细
        name: '', // 姓名
        sex: '', // 性别
        age: undefined, // 年龄
        weixin: '', // 微信
        qq: ''// qq
      },
      rules: {
        phone: [{ required: true, message: '请填写手机号！', trigger: 'blur' }, { pattern: /^1[3-9]\d{9}$/, message: '手机号格式不正确！', trigger: 'blur' }],
        channel: [{ required: true, message: '请选择渠道来源！', trigger: 'blur' }],
        name: [{ required: true, message: '请填写客户姓名！', trigger: 'blur' }]
      },
      // 渠道来源
      channelList: [{ id: '0', value: '线上活动' }, { id: '1', value: '推广介绍' }],
      // 活动信息列表
      activityList: [{ id: 1, value: '唱' }, { id: 2, value: '跳' }]
    }
  },
  created() {
  },
  methods: {
    /**
     * 添加确定事件
     */
    addClue() {
      console.log(this.form)
      this.$refs.form.validate(async key => {
        if (!key) return
        const res = await addClueApi(this.form)
        if (res.code === 500) {
          Message.error('添加失败！')
          return
        }
        Message.success('添加成功！')
        console.log(this.$parent)
        this.$parent.getClueList()
        this.closeDailog()
      })
    },
    /**
     * 关闭弹窗
     */
    closeDailog() {
      this.$emit('update:visible', false)
      this.$refs.form.resetFields()
      this.form = {
        phone: '', // 手机号
        channel: '', // 渠道来源
        details: '', // 详细
        name: '', // 姓名
        sex: '', // 性别
        age: undefined, // 年龄
        weixin: '', // 微信
        qq: ''// qq
      }
    }
  }
}
</script>

<style scoped lang='scss'>
::v-deep .el-form-item__label{
    font-weight: 500;
    color: #333!important;
}
::v-deep .el-input-number{
    width: 300px;
}
::v-deep .el-input-number .el-input__inner {
  text-align: left; //位置居左
}
::v-deep .el-dialog__header{
  background: #8DF;
}
</style>
